<html>
 <head>
  <title>Test Page for Interfaces</title>
  <script language="javascript" src="../../jsunit/app/jsUnitCore.js"></script>
  <script language="javascript" src="../compiled/ca-all.js"></script>
 </head>
 <body>
  <script language="javascript">
    function testCreation() {
		var iTest = CA.Interfaces.Create("ITest",["AlertIt","SetMessage"]);
        assertNotNull("Interface not null",iTest);
		var succeed = false;
		try{
			iTest = CA.Interfaces.Create("ITest",["AlertIt","SetMessage"]);
			succeed = true;
		}catch(e){}
		assertFalse("Creation fails with Interface existing",succeed)
    }
    function testEmpliments() {
		var iTest2 = CA.Interfaces.Create("ITest2",["AlertIt","SetMessage"]);
		var iTest3 = CA.Interfaces.Create("ITest3",["BlurtIt"]);
		var o = {AlertIt:function(){},SetMessage:function(){}};
		assertTrue("o does implement ITest2",iTest2.Check(o));
		assertFalse("o does not implement ITest3",iTest3.Check(o));
		var succeed = false;
		try{
			iTest2.Ensure(o);
			succeed = true;
		}catch(e){}
        assertTrue("o does implement ITest2",succeed);
		succeed = true;
		try{
			iTest3.Ensure(o);
			succeed = false;
		}catch(e){}
        assertTrue("Ensure o does not implement ITest3",succeed);
    }
    function testMultipleEmpliments() {
		CA.Interfaces.Create("ITest4",["AlertIt","SetMessage"]);
		CA.Interfaces.Create("ITest5",["BlurtIt"]);
		var o = {AlertIt:function(){},SetMessage:function(){},BlurtIt:function(){}};
		var o2 = {AlertIt:function(){},SetMessage:function(){}}; 
		assertTrue("o does implement ITest4,ITest5",CA.Interfaces.Check(o,"ITest4","ITest5"));
		assertFalse("o does not implement ITest4,ITest5",CA.Interfaces.Check(o2,"ITest4","ITest5"));
		var succeed = false;
		try{
			CA.Interfaces.Ensure(o,"ITest4","ITest5");
			succeed = true;
		}catch(e){}
        assertTrue("o does implement ITest4 & ITest5",succeed);
		succeed = true;
		try{
			CA.Interfaces.Ensure(o2,"ITest4","ITest5");
			succeed = false;
		}catch(e){}
        assertTrue("o2 does not implement ITest4 & ITest5",succeed);
    }
  </script>
 </body>
</html>